// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.controllers' is found in controllers.js
// angular.module('starter', ['ionic', 'starter.controllers'])
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])

.run(function($ionicPlatform) {
    $ionicPlatform.ready(function() {
        // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
        // for form inputs)
        if (window.cordova && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        }
        if (window.StatusBar) {
            // org.apache.cordova.statusbar required
            StatusBar.styleDefault();
        }
    });
})

.config(function($stateProvider, $urlRouterProvider) {


    $stateProvider

        .state('login', {
        url: '/login',
        templateUrl: 'templates/login.html',
        controller: 'LoginCtrl'
    })



    .state('pwVergessen', {
        url: '/pwVergessen',
        templateUrl: 'templates/pwVergessen.html',
        controller: 'LoginCtrl'
    })

    .state('registrieren', {
        url: "/registrieren",
        templateUrl: 'templates/registrieren.html',
        controller: 'LoginCtrl'
    })

    .state('home', {
        url: "/home",
        templateUrl: 'templates/home.html',
        controller: 'LoginCtrl'
    })

    .state('app', {
        url: "/app",
        abstract: true,
        templateUrl: "templates/menu.html",
        controller: 'AppCtrl'
    })

    .state('app.about', {
        url: "/about",
        views: {
            'menuContent': {
                templateUrl: "templates/about.html"
            }
        }
    })

    .state('app.auftragAufgeben', {
        url: "/auftragAufgeben",
        views: {
            'menuContent': {
                templateUrl: "templates/auftragAufgeben.html"
            }
        }
    })

    .state('app.auftraegeAnzeigen', {
        url: "/auftraegeAnzeigen",
        views: {
            'menuContent': {
                templateUrl: "templates/auftraegeAnzeigen.html"
            }
        }
    })

    .state('app.selectDestination', {
        url: "/selectDestination",
        views: {
            'menuContent': {
                templateUrl: "templates/selectDestination.html"
            }
        }
    })

    .state('app.uebersichtDaten', {
        url: "/uebersichtDaten",
        views: {
            'menuContent': {
                templateUrl: "templates/uebersichtDaten.html"
            }
        }
    })

    .state('app.auftragDetails', {
        url: "/auftragDetails",
        views: {
            'menuContent': {
                templateUrl: "templates/auftragDetails.html"
            }
        }
    })

    .state('app.meineAuftraege', {
        url: "/meineAuftraege",
        views: {
            'menuContent': {
                templateUrl: "templates/meineAuftraege.html"
            }
        }, 
        controller: 'meineAuftraegeCtrl'
    })

    .state('app.meineAuftraegeDetails', {
        url: "/meineAuftraegeDetails",
        views: {
            'menuContent': {
                templateUrl: "templates/meineAuftraegeDetails.html"
            }
        }
    })

    .state('app.logout', {
        url: "/logout",
        views: {
            'menuContent': {
                templateUrl: "templates/logout.html"
            }
        }
    })

    .state('app.profilAendern', {
        url: "/profilAendern",
        views: {
            'menuContent': {
                templateUrl: "templates/profilAendern.html"
            }
        }
    })

    .state('app.bewertung', {
        url: "/bewertung",
        views: {
            'menuContent': {
                templateUrl: "templates/bewertung.html"
            }
        }
    })

    

    // .state('app.registrieren', {
    //   url: "/registrieren",
    //   views: {
    //     'menuContent': {
    //       templateUrl: "templates/registrieren.html"
    //     }
    //   }
    //})

    // if none of the above states are matched, use this as the fallback

    $urlRouterProvider.otherwise('/home');

    /*$urlRouterProvider.otherwise(function() {
        if(!checkSession()) {
            $state.go('app.meineAuftraege');
        } else {
            $state.go('home');
        }
    });*/
});
/*
function checkSession() {
    var dUID = device.uuid;
    var sessionId = fromLocalStorage("sessionID");
    var sessionUId = fromLocalStorage("sessionUId");
    var ret = false;
    jQuery.ajax({
            type: "POST",
            url: "http://ba.tech-time.de/kurier/json.php",
            data: {
                action: "checkSession",
                sessionDeviceId: dUID,
                sessionUId: sessionUId,
                sessionId: sessionId
            },
            async: false
        })
        .done(function(data) {
            alert(data);
            var obj = jQuery.parseJSON(data);
            if (obj.errorcode == "0") {
                ret = true;
            }
        });

    return ret;
}*/